<template>
  <el-row style="width:100%">
    <el-col :span="20">{{ nodeData.name }}</el-col>
    <el-col :span="4">
      <el-row :gutter="20">
        <el-col :span="12" style="text-align:right">{{ nodeData.manager || '暂无' }}</el-col>
        <el-col :span="12">
          <el-dropdown @command="handleClick">
            <span class="el-dropdown-link">
              操作<i class="el-icon-arrow-down el-icon--right" />
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="add">添加子部门</el-dropdown-item>
              <el-dropdown-item v-if="!nodeData.isRoot" command="edit">查看部门</el-dropdown-item>
              <el-dropdown-item v-if="!nodeData.isRoot" command="del">删除部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
<<<<<<< HEAD
import { reqDelDepartments } from '@/api/departments'
=======
import { reqDelDEpartment } from '@/api/departments'
>>>>>>> 87f5b7a6ca4750022e7dba2d9b8c213ea16573ec
export default {
  name: 'TreeTools',
  props: {
    nodeData: {
      type: Object,
      required: true
    }
  },
  methods: {
    async handleClick(str) { // 是每一个菜单项的command标识符
<<<<<<< HEAD
      if (str === 'add') {
        // 添加 并把当前点击的数据对象以自定义方法的形式传递出去
=======
      console.log(str)
      if (str === 'add') {
        // console.log(this.nodeData) // 点击的部门信息对象
        // 添加
        // 通知父组件显示对话框,并且携带当前点击部门的信息
>>>>>>> 87f5b7a6ca4750022e7dba2d9b8c213ea16573ec
        this.$emit('show', this.nodeData)
      }
      if (str === 'edit') {
        // console.log(this.nodeData)
        // 编辑查看
<<<<<<< HEAD
        // 通知父组件展示对话框 并把当前点击的部门信息传到父组件
        this.$emit('showzsk', this.nodeData)
      }
      if (str === 'del') {
        // 删除部门
        console.log(this.nodeData)
        this.$confirm('此操作将永久删除该部门, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$message.info('点击了确定')
          // 发送删除的请求 并且携带id
          reqDelDepartments(this.nodeData.id)
          // 通知父组件重新获取部门列表
          this.$emit('getdepts')
        }).catch(() => {
          this.$message.info('已取消删除')
        })
=======
        this.$emit('edit', this.nodeData)
      }
      if (str === 'del') {
        // 删除部门
        const res = await this.$confirm('此操作将永久删除该部门, 是否继续?', '提示', {
          type: 'warning'
        }).catch(() => {})
        if (res !== 'confirm') return this.$message.info('已取消删除')
        // 删除的请求
        await reqDelDEpartment(this.nodeData.id)
        // 通知父组件重新获取
        this.$emit('reload')
>>>>>>> 87f5b7a6ca4750022e7dba2d9b8c213ea16573ec
      }
    }
  }
}
</script>

<style>

</style>
